Skip to content

fix: Strengthen error handling in qwenOAuth2.ts to prevent unhandled 'error' event#3481

Open
Ojhaharsh wants to merge 3 commits intoQwenLM:mainfrom
Ojhaharsh:fix/qwen-oauth-crash
Open

fix: Strengthen error handling in qwenOAuth2.ts to prevent unhandled 'error' event#3481
Ojhaharsh wants to merge 3 commits intoQwenLM:mainfrom
Ojhaharsh:fix/qwen-oauth-crash

Conversation

@Ojhaharsh
Copy link
Copy Markdown
Contributor

@Ojhaharsh Ojhaharsh commented Apr 20, 2026

Hi @wenshao,

As suggested in your review of #1675, this PR addresses the root cause of the crash reported in issue #1674

The Issue

The crash (Unhandled 'error' event) occurs in packages/core/src/qwen/qwenOAuth2.ts when the open package fails to spawn a browser process (common on RISC-V/OrangePi headless environments).

The Fix

I updated the launchBrowser helper function to:

  1. Explicitly check if childProcess is valid before attaching listeners.
  2. Attach the childProcess.on('error') listener immediately after await open() to minimize race conditions.
  3. Ensure errors are caught via try/catch AND the event listener, logging gracefully via debugLogger instead of crashing.

This implements your suggestion to "attach the error listener before the child has a chance to emit."

Relation to PR #1675

This is the second part of the split you requested:

--
(Fixes #1674)
Ready for review!

@@ -8,7 +8,7 @@ import crypto from 'crypto';
import path from 'node:path';
import { promises as fs } from 'node:fs';
import * as os from 'os';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] ChildProcess is only used as a type here, so this should be a type-only import to satisfy the repo's lint rule.

Suggested change
import * as os from 'os';
import type { ChildProcess } from 'node:child_process';

— gpt-5.4 via Qwen Code /review

@Ojhaharsh
Copy link
Copy Markdown
Contributor Author

Hi @wenshao,

This PR contains the robust error handling fix for qwenOAuth2.ts to prevent the Unhandled 'error' event crash on RISC-V/OrangePi environments (Issue #1674).

Status:

Lint Fixed: Updated ChildProcess to a type-only import as suggested.
All Checks Green: Lint, Tests (Mac/Ubuntu/Windows), and CodeQL are passing.
Logic Verified: The launchBrowser function now safely attaches error listeners and handles failures gracefully via debugLogger.

This addresses the root cause of the crash you identified. It is designed to be merged alongside PR #1675 (which handles the utility/test updates).

Ready for your final approval!

@Ojhaharsh Ojhaharsh requested a review from wenshao April 20, 2026 19:48
@tanzhenxin tanzhenxin added the type/bug Something isn't working as expected label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qwen-code encountered an error during initialization on OrangePi RV2

3 participants